package com.example.tables.bean;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.example.tables.service.TableAService;

import java.util.ArrayList;
import java.util.List;

public class TableReadListener implements ReadListener<TableABean> {
    List<TableABean> list = new ArrayList<>();
    private TableAService tableAService;

    public TableReadListener(TableAService tableAService) {
        this.tableAService = tableAService;
    }


    @Override
    public void invoke(TableABean tableABean, AnalysisContext analysisContext) {
        System.out.println("one line!");
        list.add(tableABean);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.printf("done!");
        for (int i = 0; i < list.size(); i++) {
            tableAService.addData(list.get(i));
            //System.out.printf(list.get(i).getA());
        }
        System.out.printf("loaded!");
    }
}
